﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Blade.Devices.Storage {
	public sealed class Partition : IBlockDevice {
		IBlockDevice parentDevice;
		long baseIndex;
		long blockCount;

		public Partition(IBlockDevice parentDevice, long baseIndex, long blockCount) {
			this.parentDevice = parentDevice;
			this.baseIndex = baseIndex;
			this.blockCount = blockCount;
		}

		public void ReadBlock(long index, byte[] block, int offset) {
			if (index > blockCount)
				throw new ArgumentOutOfRangeException("index");
			parentDevice.ReadBlock(index + baseIndex, block, offset);
		}

		public int BlockSize { get { return parentDevice.BlockSize; } }

		public long BlockCount { get { return blockCount; } }

		public FileSystemBase FileSystem { get; set; }
	}
}
